package com.xbongbong.saas.enums;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 表单设置分组下公司配置
 *
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/1/21 13:48
 * @since v1.0
 */
@Getter
public enum TemplateCompanyConfigEnum {
    // 表单设置分组下公司配置
//    CUSTOMER_NAME_CHECK_SET(RedundantTemplateTypeEnum.CUSTOMER.getCode(), TemplateConfigGroupEnum.DUPLICATE_CHECKING_SET.getCode(), CompanyConfigEnum.CUSTOMER_NAME_CHECK_SET.getName(), CompanyConfigEnum.CUSTOMER_NAME_CHECK_SET.getAlias(), FieldTypeEnum.SWITCH.getType(), ""),
//    CUSTOMER_PHONE_CHECK_SET(RedundantTemplateTypeEnum.CUSTOMER.getCode(), TemplateConfigGroupEnum.DUPLICATE_CHECKING_SET.getCode(), CompanyConfigEnum.CUSTOMER_PHONE_CHECK_SET.getName(), CompanyConfigEnum.CUSTOMER_PHONE_CHECK_SET.getAlias(), FieldTypeEnum.SWITCH.getType(), ""),
//    CUS_PHONE_RULE_SET(RedundantTemplateTypeEnum.CUSTOMER.getCode(), TemplateConfigGroupEnum.PHONE_NUMBER_SET.getCode(), CompanyConfigEnum.CUS_PHONE_RULE_SET.getName(), CompanyConfigEnum.CUS_PHONE_RULE_SET.getAlias(), FieldTypeEnum.COMBO.getType(), "仅数字,数字、字母、空格、加号、中划线、小数点、下划线及@,11位数字"),
    ;

    private Integer businessType;
    private Integer groupCode;
    private String name;
    private String alias;
    private Integer fieldType;
    private String defaultValue;

    TemplateCompanyConfigEnum(Integer businessType, Integer groupCode, String name, String alias, Integer fieldType, String defaultValue) {
        this.businessType = businessType;
        this.groupCode = groupCode;
        this.name = name;
        this.alias = alias;
        this.fieldType = fieldType;
        this.defaultValue = defaultValue;
    }

    /**
     * 获取某个分组下的公司配置
     *
     * @param groupCode 公司配置分组code
     * @return 公司配置列表
     */
    public static List<TemplateCompanyConfigEnum> getByGroupCode(Integer groupCode) {
        List<TemplateCompanyConfigEnum> templateCompanyConfigEnums = new ArrayList<>();
        for (TemplateCompanyConfigEnum templateCompanyConfigEnum : values()) {
            if (Objects.equals(templateCompanyConfigEnum.getGroupCode(), groupCode)) {
                templateCompanyConfigEnums.add(templateCompanyConfigEnum);
            }
        }
        return templateCompanyConfigEnums;
    }

    /**
     * 获取某个业务下的公司配置
     *
     * @param businessType 业务类型
     * @return 公司配置列表
     */
    public static List<String> getByBusinessType(Integer businessType) {
        List<String> templateCompanyConfigEnums = new ArrayList<>();
        for (TemplateCompanyConfigEnum templateCompanyConfigEnum : values()) {
            if (Objects.equals(templateCompanyConfigEnum.getBusinessType(), businessType)) {
                templateCompanyConfigEnums.add(templateCompanyConfigEnum.getAlias());
            }
        }
        return templateCompanyConfigEnums;
    }

    public static TemplateCompanyConfigEnum getByAlias(String alias) {
        for (TemplateCompanyConfigEnum templateCompanyConfigEnum : values()) {
            if (Objects.equals(templateCompanyConfigEnum.getAlias(), alias)) {
                return templateCompanyConfigEnum;
            }
        }
        return null;
    }
}
